const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    id: null,
    imgUrl: app.globalData.url + "downLoad?filename=",
    consult: null,
    specialty: [],
    chargeData: [],
    appointmentData: [],
    userMarkData: [],
    courseData: []
  },
  getData() {
    this.getConsultSpecialtyData();
    this.getChargeData();
    this.getAppointmentData();
    this.getUserMarkData();
    this.getCourseData();
  },
  // 咨询师、擅长领域
  getConsultSpecialtyData() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'consultspecialty/find?consult_id=' + this.data.id,
      success(res) {
        // console.log(res.data.data.list)
        let arr = [];
        res.data.data.list.forEach(item => {
          arr.push(item.specialty.name);
        });
        that.setData({
          consult: res.data.data.list[0].consult,
          specialty: arr
        })
      },
    })
  },
  // 收费标准
  getChargeData() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'charge/find?consult_id=' + this.data.id,
      success(res) {
        // console.log(res.data.data.list)
        let arr = [];
        if (res.data.data.list != null) {
          res.data.data.list.forEach(item => {
            let elment = {
              "til": item.chargetype.name,
              "count": item.countNumber,
              "money": item.chargePrice
            };
            arr.push(elment);
          });
        }
        that.setData({
          chargeData: arr
        })
      },
    })
  },
  // 回复留言
  getAppointmentData() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'appointment/find?consult_id=' + this.data.id,
      success(res) {
        // console.log(res.data.data)
        let arr = [];
        if (res.data.data != null) {
          res.data.data.forEach(item => {
            let elment = {
              "content": item.content,
              "reply": item.reply
            };
            arr.push(elment);
          });
        }
        that.setData({
          appointmentData: arr
        })
      },
    })
  },
  // 用户评价
  getUserMarkData() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'userMark/findByPage?consult_id=' + this.data.id,
      success(res) {
        // console.log(res.data.data.list)
        let arr = [];
        if (res.data.data.list != null) {
          res.data.data.list.forEach(item => {
            let elment = {
              "name": item.user.nickName,
              "markStar": item.markStar,
              "createTime": item.createTime,
              "content": item.content
            };
            arr.push(elment);
          });
        }
        that.setData({
          userMarkData: arr
        })
      },
    })
  },
  // 发布课程
  getCourseData() {
    let that = this;
    wx.request({
      url: app.globalData.url + 'Course/selectByConsultId?teacher_id=' + this.data.id,
      success(res) {
        // console.log(res.data.data.list)
        let arr = [];
        if (res.data.data.list != null) {
          res.data.data.list.forEach(item => {
            let elment = {
              "courseName": item.courseName,
              "tabularChart": item.tabularChart
            };
            arr.push(elment);
          });
        }
        that.setData({
          courseData: arr
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.data.id = options.id
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})